// SettingDialog.cpp : implementation file
//

#include "stdafx.h"
#include "GetFilenames.h"
#include "SettingDialog.h"


// SettingDialog dialog

IMPLEMENT_DYNAMIC(SettingDialog, CDialog)

SettingDialog::SettingDialog(CWnd* pParent /*=NULL*/)
	: CDialog(SettingDialog::IDD, pParent)
	, strSmtpServer(_T(""))
	, strPrjname(_T(""))
	, strSmtpPort(_T(""))
	, strSmtpUser(_T(""))
	, strSmtpPassword(_T(""))
	, strPop3Server(_T(""))
	, strPop3Port(_T(""))
	, strPop3User(_T(""))
	, strPop3Password(_T(""))
	, bPop3SameAsSmtp(FALSE)
{
}

SettingDialog::~SettingDialog()
{
}

void SettingDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, mEditPrjname);
	DDX_Control(pDX, IDC_EDIT2, mEditSmtpserver);
	DDX_Control(pDX, IDC_EDIT3, mEditSmtpport);
	DDX_Control(pDX, IDC_EDIT4, mEditPop3server);
	DDX_Control(pDX, IDC_EDIT5, mEditPop3port);
	DDX_Control(pDX, IDC_EDIT6, mEditSMTPUser);
	DDX_Control(pDX, IDC_EDIT7, mEditSMTPPassword);
	DDX_Text(pDX, IDC_EDIT2, strSmtpServer);
	DDX_Text(pDX, IDC_EDIT1, strPrjname);
	DDX_Text(pDX, IDC_EDIT3, strSmtpPort);
	DDX_Text(pDX, IDC_EDIT6, strSmtpUser);
	DDX_Text(pDX, IDC_EDIT7, strSmtpPassword);
	DDX_Control(pDX, IDC_CHECK1, mCheckPop3SameAsSmtp);
	DDX_Control(pDX, IDC_EDIT8, mEditPop3User);
	DDX_Control(pDX, IDC_EDIT9, mEditPop3Password);
	DDX_Text(pDX, IDC_EDIT4, strPop3Server);
	DDX_Text(pDX, IDC_EDIT5, strPop3Port);
	DDX_Text(pDX, IDC_EDIT8, strPop3User);
	DDX_Text(pDX, IDC_EDIT9, strPop3Password);
	DDX_Check(pDX, IDC_CHECK1, bPop3SameAsSmtp);
}


BEGIN_MESSAGE_MAP(SettingDialog, CDialog)
	ON_BN_CLICKED(IDC_CHECK1, &SettingDialog::OnBnClickedCheck1)
	ON_NOTIFY(BCN_HOTITEMCHANGE, IDC_CHECK1, &SettingDialog::OnBnHotItemChangeCheck1)
END_MESSAGE_MAP()


// SettingDialog message handlers

void SettingDialog::SetSmtpInfo(TCHAR* server, int port, TCHAR* user, TCHAR* password)
{
	strSmtpServer = server;
	strSmtpPort.Format(_T("%d"), port);
	strSmtpUser = user;
	strSmtpPassword = password;
	if(bPop3SameAsSmtp)
	{
		strPop3Server = strSmtpServer;
		strPop3Server.Replace(_T("smtp"), _T("pop3"));		
		strPop3Port = _T("110");
		strPop3User = strSmtpUser;
		strPop3Password = strSmtpPassword;
	}
}

void SettingDialog::GetSmtpInfo(string& server, int& port, string& user, string& password)
{
	server.assign((LPCTSTR)strSmtpServer);
	port = atoi((LPCTSTR)strSmtpPort);
	user.assign((LPCTSTR)strSmtpUser);
	password.assign((LPCTSTR)strSmtpPassword);
}

void SettingDialog::SetPop3Info(TCHAR* server, int port, TCHAR* user, TCHAR* password)
{
}

void SettingDialog::GetPop3Info(string& server, int& port, string& user, string& password)
{
}

void SettingDialog::OnBnClickedCheck1()
{
	// TODO: Add your control notification handler code here
	if( mCheckPop3SameAsSmtp.GetCheck() )
	{
		mEditPop3server.EnableWindow(FALSE);
		mEditPop3port.EnableWindow(FALSE);
		mEditPop3User.EnableWindow(FALSE);
		mEditPop3Password.EnableWindow(FALSE);
		
		strPop3Server = strSmtpServer;
		strPop3Server.Replace(_T("smtp"), _T("pop3"));		
		strPop3Port = _T("110");
		strPop3User = strSmtpUser;
		strPop3Password = strSmtpPassword;
	}
	else
	{
		mEditPop3server.EnableWindow(TRUE);
		mEditPop3port.EnableWindow(TRUE);
		mEditPop3User.EnableWindow(TRUE);
		mEditPop3Password.EnableWindow(TRUE);
	}
}

void SettingDialog::OnBnHotItemChangeCheck1(NMHDR *pNMHDR, LRESULT *pResult)
{
	// This feature requires Internet Explorer 6 or greater.
	// The symbol _WIN32_IE must be >= 0x0600.
	LPNMBCHOTITEM pHotItem = reinterpret_cast<LPNMBCHOTITEM>(pNMHDR);
	// TODO: Add your control notification handler code here
	AfxMessageBox(_T("df"));
	*pResult = 0;
}

void SettingDialog::SetProjectname(TCHAR* prjname)
{
	strPrjname = prjname;
}
